<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class NowRunning {

	var $data = array();
	var $ci;
	var $name = 'nowRunning';

        function __construct()
	{
                $this->ci = &get_instance();
                $this->ci->load->helper('date');
		$this->ci->load->library('Webinar');
		$this->ci->load->model('Check', 'check');
                //$this->ci->load->library('BigBlueButton', NULL, 'bbb')
		$this->ci->load->config('eclass_cfg');
                //$this->load->helper('data');
                $this->data['base_url'] = @$this->ci->base_url;
                $this->data['url'] = $this->ci->config->item('bbb_url');
                $this->data['salt'] = $this->ci->config->item('salt');
                $this->data['UID'] = $this->ci->session->userdata('UID');
		$this->data['role'] = $this->ci->session->userdata('role');
	}

	function init($param)
	{
		$this->data['container'] = @$param;
	}

	function data()
	{
                $dt['webinar'] = $this->ci->webinar->now_running($this->data['url'], $this->data['salt']);

		if(!$dt['webinar']) $dt['message'][0] = array('text' => "На данный момент вебинаров не проводится.");
		else $dt += array('message' => array()); // TODO: And Fix IT!
		//$this->ci->output->set_output(json_encode($data));
		return json_encode($dt);
	}

	function load()
	{
		$data['base_url'] = base_url();
		$data['container'] = @$this->data['container'];
		$gadget = $this->ci->parser->parse('templates/'.$this->name.'.html', $data, true);
		return $gadget;
	}
}
